#!/bin/bash

# 构建 WASM 包
echo "Building WASM package..."
wasm-pack build --target bundler --release --scope krwu --out-name index

# 检查构建是否成功
if [ $? -eq 0 ]; then
    echo ""
    echo "✓ Build successful"
    echo "✓ Generated scoped package: @krwu/img-resize-wasm"
    echo ""
    echo "Fixing package.json..."
    node fix-package-json.cjs
    
    if [ $? -eq 0 ]; then
        echo ""
        echo "✓ All done!"
        echo ""
        echo "Next steps:"
        echo "  cd pkg"
        echo "  npm publish --access public"
    else
        echo ""
        echo "✗ Failed to fix package.json"
        exit 1
    fi
else
    echo ""
    echo "✗ Build failed"
    exit 1
fi
